from PIL import Image
from pytesseract import pytesseract
import os
from docx import Document
from google.cloud import vision
import io
class ImageReadToWord:
    def todo(self):
        os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/your/service-account-file.json"

        client=vision.ImageAnnotatorClient()

        imagePath = r'C:\Users\ACLang\Pictures\ll\微信图片_20240726190834.jpg'
        with io.open(imagePath,'rb') as image_file:
            content=image_file.read()

        image = vision.types.Image(content=content)

        # 调用文本检测API
        response = client.text_detection(image=image)
        texts = response.text_annotations

        # 打印检测到的文本
        print('Texts:')

        for text in texts:
            print('\n"{}"'.format(text.description))

            # 获取文本的位置信息（‌可选）‌
            vertices = (['({},{})'.format(vertex.x, vertex.y)
                         for vertex in text.bounding_poly.vertices])

            print('bounds: {}'.format(','.join(vertices)))
if __name__ == '__main__':
    im=ImageReadToWord()
    # path=input("输入图片地址：")
    im.todo()